<?php

Loader::using("ext::libs::restful::RESTfulClient");
Loader::using("Models::Entities::Usuarios");

/**
 * Description of UsuariosService
 *
 * @author JeyDotC
 */
class UsuariosService extends RESTfulClient {

    public function AgregarUsuario(Usuarios $usuario) {
        $data = $this->getSerializer()->serialize($usuario);
        $response = $this->call("/Add/{$usuario->getUserName()}", "POST", $data);
        return $this->getDeserializer()->deserialize("bool", $response);
    }


    public function ActualizarContrasena($password, $username, $newPassword) {
        $data = $this->getSerializer()->serialize(
                array(
                    "password" => $password,
                    "username" => $username,
                    "newPassword" => $newPassword,
                ));
        
        $this->call("/UpdatePassword", "PUT", $data);
    }

    public function AgregarRol($username, $idRol) {
        $response = $this->call("/AddRol/$username/$idRol", "PUT");
        return $response;
    }
    
    public function QuitarRol($username, $idRol) {
        $response = $this->call("/QuitarRol/$username/$idRol", "PUT");
        return $response;
    }
    
    public function GetUsuarios($user, $pass) {
        $response = $this->call("/GetUsuarios", "POST", $this->getSerializer()->serialize(array(
            "password" => md5($pass),
            "username" => $user,
        )));
        return $this->getDeserializer()->deserialize("array", $response);
    }
    
    public function GetRoles($user) {
        $response = $this->call("/GetRoles/$user");
        return $this->getDeserializer()->deserialize("Roles", $response);
    }
    
    public function GetRolesDisponibles() {
        $response = $this->call("/");
        return $this->getDeserializer()->deserialize("Roles", $response);
    }
    
    public function EliminarUsuario($id) {
        $response = $this->call("/$id", "DELETE");
        return $this->getDeserializer()->deserialize("bool", $response);
    }
}

?>
